package com.gao;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //获取类的字节码对象
        Class<?> student = Class.forName("com.domain.Student");
        //反射构造方法
        Constructor<?>[] constructors = student.getConstructors();
        for (int i = 0; i < constructors.length; i++) {
            System.out.println(constructors[i]);
        }
         Constructor<?> constructor = student.getDeclaredConstructor(String.class,int.class);
        System.out.println(constructor);
         Object o = constructor.newInstance("张三",23);
        System.out.println(o);
    }
}
